﻿
Ext.define('StudentDataModel', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'LxGUID', mapping: 'LxGUID' },
        { name: 'TaskGUID', mapping: 'TaskGUID' },
        { name: 'LxDate', mapping: 'LxDate' },
        { name: 'Lxr', mapping: 'Lxr' },
        { name: 'TalkContent', mapping: 'TalkContent' },
        { name: 'Djr', mapping: 'Djr' }
    ]
});



Ext.application({
    extend: 'Ext.app.Application',

    models: [
        // TODO: add global / shared modes here
    ],
    stores: [
        // TODO: add global / shared stores here
    ],
    views: [
        // TODO: add global / shared views here
    ],
    controllers: [],
    name: 'Demo',
});

Ext.onReady(function () {
    // Store data
    var myData = [
        { LxGUID: "14695645-CFA1-4378-A096-2619192FBCE1", TaskGUID: "14695645-CFA1-4378-A096-2619192FBCE1", LxDate: "2019-12-30 00:00:00.000", Lxr: "1", TalkContent: "1", Djr: "1"}
        //{ name: "Vinit", age: "18", marks: "95" },
        //{ name: "Anand", age: "20", marks: "68" },
        //{ name: "Niharika", age: "21", marks: "86" },
        //{ name: "Manali", age: "22", marks: "57" }
    ];
    // Creation of first grid store
    var gridStore = Ext.create('Ext.data.Store', {
        model: 'StudentDataModel',
        data: myData

    });

    Ext.create('Ext.panel.Panel', {
        renderTo: 'textpanel',
        layout: {
            type: 'table',
            columns: 2
        },
        items: [
            {
                id: 'LxGUID',
                xtype: 'textfield',
                fieldLabel: 'LxGUID',
                name: 'LxGUID',
                width: 400,
                emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
            {
                id: 'TaskGUID',
                xtype: 'textfield',
                fieldLabel: 'TaskGUID',
                name: 'TaskGUID',
                width: 400,
                //emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
            {
                id: 'LxDate',
                xtype: 'textfield',
                fieldLabel: 'LxDate',
                name: 'LxDate',
                width: 400,
                //emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
            {
                id: 'Lxr',
                xtype: 'textfield',
                fieldLabel: 'Lxr',
                name: 'Lxr',
                width: 400,
                //emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
            {
                id: 'TalkContent',
                xtype: 'textfield',
                fieldLabel: 'TalkContent',
                name: 'TalkContent',
                width: 400,
                //emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
            {
                id: 'Djr',
                xtype: 'textfield',
                fieldLabel: 'Djr',
                name: 'Djr',
                width: 400,
                //emptyText: '请输入LxGUID',//相当于placeholder，提示文字
                allowBlank: false
            },
        ]
    });



    Ext.create('Ext.panel.Panel', {
        //controller: 'demoController',
        renderTo: 'btnDiv',
        items: [
            {
                xtype: 'button',
                iconCls: 'Applicationviewlist',
                text: '查询',
                listeners: {
                    'click': function () {
                        var me = this;
                        var LxGUID = Ext.getCmp('LxGUID').getValue();
                        var json = '{LxGUID: "' + LxGUID + '", Type: "3"}';
                        Ext.Ajax.request({
                            url: '/Test/ApiTest',
                            params: { jsonData: json },
                            success: function (response) {
                                // loadMask.destroy();
                                //alert(response.responseText);
                                /*ar responseData = Ext.JSON.decode(response.responseText);*/
                                if (response != null) {
                                    alert(response.responseText);
                                }
                                else {
                                    Ext.Msg.alert('提示', response);
                                }
                            },
                            failure: function () {
                                Ext.Msg.alert('提示', '连接失败!');
                            }
                        });
                    }
                }
            },
            {
                xtype: 'button',
                labelStyle: "text-align:center;",
                iconCls: 'Applicationviewlist',
                text: '新增',
                listeners: {
                    'click': function () {
                        var LxGUID = Ext.getCmp('LxGUID').getValue();
                        var TaskGUID = Ext.getCmp('TaskGUID').getValue();
                        var LxDate = Ext.getCmp('LxDate').getValue();
                        var Lxr = Ext.getCmp('Lxr').getValue();
                        var TalkContent = Ext.getCmp('TalkContent').getValue();
                        var Djr = Ext.getCmp('Djr').getValue();

                        var json = '{LxGUID: "' + LxGUID + '", Type: "1", TaskGUID: "' + TaskGUID + '", LxDate: "' + LxDate + '", Lxr: "' + Lxr + '", TalkContent: "' + TalkContent + '", Djr: "' + Djr + '"}';

                        Ext.Ajax.request({
                            url: '/Test/ApiTest',
                            params: { jsonData: json },
                            success: function (response) {
                                // loadMask.destroy();
                                //alert(response.responseText);
                                /*ar responseData = Ext.JSON.decode(response.responseText);*/
                                if (response != null) {
                                    alert(response.responseText);
                                }
                                else {
                                    Ext.Msg.alert('提示', response);
                                }
                            },
                            failure: function () {
                                Ext.Msg.alert('提示', '连接失败!');
                            }
                        });
                    }
                }
            },
            {
                xtype: 'button',
                labelStyle: "text-align:center;",
                iconCls: 'Applicationviewlist',
                text: '删除',
                listeners: {
                    'click': function () {
                        var me = this;
                        var LxGUID = Ext.getCmp('LxGUID').getValue();
                        var json = '{LxGUID: "' + LxGUID + '", Type: "2"}';
                        Ext.Ajax.request({
                            url: '/Test/ApiTest',
                            params: { jsonData: json },
                            success: function (response) {
                                // loadMask.destroy();
                                //alert(response.responseText);
                                /*ar responseData = Ext.JSON.decode(response.responseText);*/
                                if (response != null) {
                                    alert(response.responseText);
                                }
                                else {
                                    Ext.Msg.alert('提示', response);
                                }
                            },
                            failure: function () {
                                Ext.Msg.alert('提示', '连接失败!');
                            }
                        });
                    }
                }
            },
            {
                xtype: 'button',
                labelStyle: "text-align:center;",
                iconCls: 'Applicationviewlist',
                text: '修改',
                listeners: {
                    'click': function () {
                        var LxGUID = Ext.getCmp('LxGUID').getValue();
                        var TaskGUID = Ext.getCmp('TaskGUID').getValue();
                        var LxDate = Ext.getCmp('LxDate').getValue();
                        var Lxr = Ext.getCmp('Lxr').getValue();
                        var TalkContent = Ext.getCmp('TalkContent').getValue();
                        var Djr = Ext.getCmp('Djr').getValue();

                        var json = '{LxGUID: "' + LxGUID + '", Type: "5", TaskGUID: "' + TaskGUID + '", LxDate: "' + LxDate + '", Lxr: "' + Lxr + '", TalkContent: "' + TalkContent + '", Djr: "' + Djr + '"}';
                        console.log(json);
                        Ext.Ajax.request({
                            url: '/Test/ApiTest',
                            params: { jsonData: json },
                            success: function (response) {
                                // loadMask.destroy();
                                //alert(response.responseText);
                                /*ar responseData = Ext.JSON.decode(response.responseText);*/
                                if (response != null) {
                                    alert(response.responseText);
                                }
                                else {
                                    Ext.Msg.alert('提示', response);
                                }
                            },
                            failure: function () {
                                Ext.Msg.alert('提示', '连接失败!');
                            }
                        });
                    }
                }
            }
        ]
    })

    // Creation of first grid
    Ext.create('Ext.grid.Panel', {
        id: 'gridId',
        store: gridStore,
        stripeRows: true,
        title: 'Test Grid', // Title for the grid
        renderTo: 'gridDiv', // Div id where the grid has to be rendered
        //width: 600,
        collapsible: true, // property to collapse grid
        enableColumnMove: true, // property which alllows column to move to different position by dragging that column.
        enableColumnResize: true, // property which allows to resize column run time.
        columns:
            [{
                header: "LxGUID",
                dataIndex: 'LxGUID',
                flex: 1,  		 // property defines the amount of space this column is going to take in the grid container with respect to all.	
                sortable: true, // property to sort grid column data. 
                hideable: true  // property which allows column to be hidden run time on user request.
                },
                {
                    header: "TaskGUID",
                    dataIndex: 'TaskGUID',
                    flex: .5,
                    sortable: true,
                    hideable: false // this column will not be available to be hidden.
                },
                {
                    header: "LxDate",
                    dataIndex: 'LxDate',
                    flex: .5,
                    sortable: true,
                    hideable: false // this column will not be available to be hidden.
                },
                {
                    header: "Lxr",
                    dataIndex: 'Lxr',
                    flex: .5,
                    sortable: true,
                    hideable: false // this column will not be available to be hidden.
                },
                {
                    header: "TalkContent",
                    dataIndex: 'TalkContent',
                    flex: .5,
                    sortable: true,
                    hideable: false // this column will not be available to be hidden.
                },
                {
                    header: "Djr",
                    dataIndex: 'Djr',
                    flex: .5,
                    sortable: true,
                    hideable: false,
                // renderer is used to manipulate data based on some conditions here who ever has marks greater than 75 will be displayed as 'Distinction' else 'Non Distinction'.
                //renderer: function (value, metadata, record, rowIndex, colIndex, store) {
                //    if (value > 75) {
                //        return "Distinction";
                //    } else {
                //        return "Non Distinction";
                //    }
                //}
                }],
        listeners: {
            'select': function (rowModel, record) {
                var data = rowModel.getLastSelected();

                Ext.getCmp('LxGUID').setValue(data.data.LxGUID);
                Ext.getCmp('TaskGUID').setValue(data.data.TaskGUID);
                Ext.getCmp('LxDate').setValue(data.data.LxDate);
                Ext.getCmp('Lxr').setValue(data.data.Lxr);
                Ext.getCmp('TalkContent').setValue(data.data.TalkContent);
                Ext.getCmp('Djr').setValue(data.data.Djr);

                console.log("data:", data);
            }
        }
    });
   
});


